package org.jeecg.modules.dicBeGoodAtNew.controller;

import java.util.Arrays;
import java.util.List;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.jeecg.common.api.vo.Result;
import org.jeecg.common.system.query.QueryGenerator;
import org.jeecg.common.util.oConvertUtils;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import lombok.extern.slf4j.Slf4j;

import org.jeecg.common.system.base.controller.JeecgController;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.jeecg.common.aspect.annotation.AutoLog;

 /**
 * @Description: dic_be_good_at
 * @Author: jeecg-boot
 * @Date:   2021-08-13
 * @Version: V1.0
 */
@Api(tags="分类设置")
@RestController
@RequestMapping("/dicBeGoodAtNew/dicBeGoodAt")
@Slf4j
public class DicBeGoodAtController extends JeecgController<org.jeecg.common.modules.dicBeGoodAtNew.entity.DicBeGoodAtNew, org.jeecg.common.modules.dicBeGoodAtNew.service.IDicBeGoodAtNewService>{
	@Autowired
	private org.jeecg.common.modules.dicBeGoodAtNew.service.IDicBeGoodAtNewService dicBeGoodAtService;

	/**
	 * 分页列表查询
	 *
	 * @param dicBeGoodAtNew
	 * @param pageNo
	 * @param pageSize
	 * @param req
	 * @return
	 */
	@AutoLog(value = "dic_be_good_at-分页列表查询")
	@ApiOperation(value="dic_be_good_at-分页列表查询", notes="dic_be_good_at-分页列表查询")
	@GetMapping(value = "/rootList")
	public Result<?> queryPageList(org.jeecg.common.modules.dicBeGoodAtNew.entity.DicBeGoodAtNew dicBeGoodAtNew,
								   @RequestParam(name="pageNo", defaultValue="1") Integer pageNo,
								   @RequestParam(name="pageSize", defaultValue="10") Integer pageSize,
								   HttpServletRequest req) {
		String parentId = dicBeGoodAtNew.getParentId()+"";
		if (oConvertUtils.isEmpty(parentId)) {
			parentId = "0";
		}
		dicBeGoodAtNew.setParentId(null);
		QueryWrapper<org.jeecg.common.modules.dicBeGoodAtNew.entity.DicBeGoodAtNew> queryWrapper = QueryGenerator.initQueryWrapper(dicBeGoodAtNew, req.getParameterMap());
		// 使用 eq 防止模糊查询
		queryWrapper.eq("parent_id", parentId);
		Page<org.jeecg.common.modules.dicBeGoodAtNew.entity.DicBeGoodAtNew> page = new Page<org.jeecg.common.modules.dicBeGoodAtNew.entity.DicBeGoodAtNew>(pageNo, pageSize);
		IPage<org.jeecg.common.modules.dicBeGoodAtNew.entity.DicBeGoodAtNew> pageList = dicBeGoodAtService.page(page, queryWrapper);
		return Result.ok(pageList);
	}

	 /**
      * 获取子数据
      * @param
      * @param req
      * @return
      */
	@AutoLog(value = "dic_be_good_at-获取子数据")
	@ApiOperation(value="dic_be_good_at-获取子数据", notes="dic_be_good_at-获取子数据")
	@GetMapping(value = "/childList")
	public Result<?> queryPageList(org.jeecg.common.modules.dicBeGoodAtNew.entity.DicBeGoodAtNew dicBeGoodAtNew, HttpServletRequest req) {
		QueryWrapper<org.jeecg.common.modules.dicBeGoodAtNew.entity.DicBeGoodAtNew> queryWrapper = QueryGenerator.initQueryWrapper(dicBeGoodAtNew, req.getParameterMap());
		List<org.jeecg.common.modules.dicBeGoodAtNew.entity.DicBeGoodAtNew> list = dicBeGoodAtService.list(queryWrapper);
		IPage<org.jeecg.common.modules.dicBeGoodAtNew.entity.DicBeGoodAtNew> pageList = new Page<>(1, 10, list.size());
        pageList.setRecords(list);
		return Result.ok(pageList);
	}

    /**
      * 批量查询子节点
      * @param parentIds 父ID（多个采用半角逗号分割）
      * @return 返回 IPage
      * @param parentIds
      * @return
      */
	@AutoLog(value = "dic_be_good_at-批量获取子数据")
    @ApiOperation(value="dic_be_good_at-批量获取子数据", notes="dic_be_good_at-批量获取子数据")
    @GetMapping("/getChildListBatch")
    public Result getChildListBatch(@RequestParam("parentIds") String parentIds) {
        try {
            QueryWrapper<org.jeecg.common.modules.dicBeGoodAtNew.entity.DicBeGoodAtNew> queryWrapper = new QueryWrapper<>();
            List<String> parentIdList = Arrays.asList(parentIds.split(","));
            queryWrapper.in("parent_id", parentIdList);
            List<org.jeecg.common.modules.dicBeGoodAtNew.entity.DicBeGoodAtNew> list = dicBeGoodAtService.list(queryWrapper);
            IPage<org.jeecg.common.modules.dicBeGoodAtNew.entity.DicBeGoodAtNew> pageList = new Page<>(1, 10, list.size());
            pageList.setRecords(list);
            return Result.ok(pageList);
        } catch (Exception e) {
            log.error(e.getMessage(), e);
            return Result.error("批量查询子节点失败：" + e.getMessage());
        }
    }

	/**
	 *   添加
	 *
	 * @param dicBeGoodAtNew
	 * @return
	 */
	@AutoLog(value = "dic_be_good_at-添加")
	@ApiOperation(value="dic_be_good_at-添加", notes="dic_be_good_at-添加")
	@PostMapping(value = "/add")
	public Result<?> add(@RequestBody org.jeecg.common.modules.dicBeGoodAtNew.entity.DicBeGoodAtNew dicBeGoodAtNew) {
		dicBeGoodAtService.addDicBeGoodAt(dicBeGoodAtNew);
		return Result.ok("添加成功！");
	}

	/**
	 *  编辑
	 *
	 * @param dicBeGoodAtNew
	 * @return
	 */
	@AutoLog(value = "dic_be_good_at-编辑")
	@ApiOperation(value="dic_be_good_at-编辑", notes="dic_be_good_at-编辑")
	@PutMapping(value = "/edit")
	public Result<?> edit(@RequestBody org.jeecg.common.modules.dicBeGoodAtNew.entity.DicBeGoodAtNew dicBeGoodAtNew) {
		dicBeGoodAtService.updateDicBeGoodAt(dicBeGoodAtNew);
		return Result.ok("编辑成功!");
	}

	/**
	 *   通过id删除
	 *
	 * @param id
	 * @return
	 */
	@AutoLog(value = "dic_be_good_at-通过id删除")
	@ApiOperation(value="dic_be_good_at-通过id删除", notes="dic_be_good_at-通过id删除")
	@DeleteMapping(value = "/delete")
	public Result<?> delete(@RequestParam(name="id",required=true) String id) {
		dicBeGoodAtService.deleteDicBeGoodAt(id);
		return Result.ok("删除成功!");
	}

	/**
	 *  批量删除
	 *
	 * @param ids
	 * @return
	 */
	@AutoLog(value = "dic_be_good_at-批量删除")
	@ApiOperation(value="dic_be_good_at-批量删除", notes="dic_be_good_at-批量删除")
	@DeleteMapping(value = "/deleteBatch")
	public Result<?> deleteBatch(@RequestParam(name="ids",required=true) String ids) {
		this.dicBeGoodAtService.removeByIds(Arrays.asList(ids.split(",")));
		return Result.ok("批量删除成功！");
	}

	/**
	 * 通过id查询
	 *
	 * @param id
	 * @return
	 */
	@AutoLog(value = "dic_be_good_at-通过id查询")
	@ApiOperation(value="dic_be_good_at-通过id查询", notes="dic_be_good_at-通过id查询")
	@GetMapping(value = "/queryById")
	public Result<?> queryById(@RequestParam(name="id",required=true) String id) {
		org.jeecg.common.modules.dicBeGoodAtNew.entity.DicBeGoodAtNew dicBeGoodAtNew = dicBeGoodAtService.getById(id);
		if(dicBeGoodAtNew ==null) {
			return Result.error("未找到对应数据");
		}
		return Result.ok(dicBeGoodAtNew);
	}

    /**
    * 导出excel
    *
    * @param request
    * @param dicBeGoodAtNew
    */
    @RequestMapping(value = "/exportXls")
    public ModelAndView exportXls(HttpServletRequest request, org.jeecg.common.modules.dicBeGoodAtNew.entity.DicBeGoodAtNew dicBeGoodAtNew) {
		return super.exportXls(request, dicBeGoodAtNew, org.jeecg.common.modules.dicBeGoodAtNew.entity.DicBeGoodAtNew.class, "dic_be_good_at");
    }

    /**
      * 通过excel导入数据
    *
    * @param request
    * @param response
    * @return
    */
    @RequestMapping(value = "/importExcel", method = RequestMethod.POST)
    public Result<?> importExcel(HttpServletRequest request, HttpServletResponse response) {
		return super.importExcel(request, response, org.jeecg.common.modules.dicBeGoodAtNew.entity.DicBeGoodAtNew.class);
    }

}
